from bs4 import BeautifulSoup
import requests
import json
from GKData import GKData
from MyEncoder import MyEncoder

base_url = 'https://www.gift-gift.jp'
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
}

all_datas = []

count = 0


def start():
    response = requests.get(f"{base_url}/product_json_merge.php", headers=headers)
    json_data = json.loads(response.text)
    writeToFile(toJson(json_data['items']), 'Gift')


def writeToFile(data, fileName):
    with open(f'./data/{fileName}.json', 'a') as file:
        file.write(data)


def toJson(obj):
    return json.dumps(obj, cls=MyEncoder)


start()
